package main

import (
	"log"
	"time"

	"github.com/gomodule/redigo/redis"
)

//使用redis redigo连接池
func main() {
	pool := &redis.Pool{
		MaxIdle:   4,
		MaxActive: 4,
		Dial: func() (redis.Conn, error) {
			c, err := redis.Dial("tcp", "81.68.186.20:6379", redis.DialDatabase(1), redis.DialPassword("ffdd2021@"))
			if err != nil {
				log.Println("redis.Dial err = ", err)
				return nil, err
			}
			return c, err
		},
		IdleTimeout: time.Second,
		Wait:        true,
	}
	defer pool.Close()
	c := pool.Get()
	defer c.Close()
	s, err := redis.String(c.Do("get", "ding_test"))
	if err != nil {
		log.Println("redis.String err = ", err)
	}
	log.Println("value:", s)

}
